package com.sambo.inspection.component;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.sambo.inspection.R;

public class TitlePopup extends PopupWindow implements View.OnClickListener {

	private Context mContext;

	private OnItemOnClickListener mItemOnClickListener;

	private LinearLayout llSelectInfo;
	private LinearLayout llOption;
//	private LinearLayout llLogout;

	public interface OnItemOnClickListener{
		void onItemClick(int position);
	}

	public TitlePopup(Context context){
		this(context, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	}
	
	public TitlePopup(Context context, int width, int height){
		this.mContext = context;
		setFocusable(true);
		setTouchable(true);
		setOutsideTouchable(true);
		setWidth(width);
		setHeight(height);
		setBackgroundDrawable(new ColorDrawable());
		setContentView(LayoutInflater.from(mContext).inflate(R.layout.popup_title, null));
		initUI();
	}
	
	private void initUI() {
		llSelectInfo = (LinearLayout) getContentView().findViewById(R.id.ll_select_info);
		llOption = (LinearLayout) getContentView().findViewById(R.id.ll_option);
//		llLogout = (LinearLayout) getContentView().findViewById(R.id.ll_logout);

		llSelectInfo.setOnClickListener(this);
		llOption.setOnClickListener(this);
//		llLogout.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.ll_select_info:
				forwardPage(0);
				break;
			case R.id.ll_option:
				forwardPage(1);
				break;
//			case R.id.ll_logout:
//				forwardPage(2);
//				break;
		}
	}

	private void forwardPage(int type) {
		dismiss();
		if (mItemOnClickListener != null)
			mItemOnClickListener.onItemClick(type);
	}
	
	public void setItemOnClickListener(OnItemOnClickListener onItemOnClickListener){
		this.mItemOnClickListener = onItemOnClickListener;
	}

	public void show(View view){
		showAsDropDown(view);
	}

}
